package com.mgface.springcloud.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wanyuxiang
 * @version 1.0
 * @project springcloudCollection
 * @create 2018-08-16 13:56
 **/
@Component
public class RequesFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        RequestContext contxt =  RequestContext.getCurrentContext();
        HttpServletRequest request =  contxt.getRequest();
        String token = request.getParameter("token");
        if (token == null || !token.equals("1")){
            contxt.setResponseBody("token error!");
            contxt.setSendZuulResponse(false);
        }
        return null;
    }

}
